package com.chazz.utils;

import com.chazz.Do.GoodsInfo;
import com.chazz.dao.impl.DiscountDaoImpl;
import com.chazz.dao.impl.PriceDaoImpl;
import com.chazz.service.impl.CoupondServiceImpl;
import com.chazz.service.impl.IsDiscountServiceImpl;

/**
 * 描述:计算商品小计价格
 *
 * @author Chazz
 * @create 2020-09-24 17:21
 */
public class TotalPriceUtils {
    /**
     * description: count 通过商品信息和用户信息，对用户下单的商品计算优惠之后的价格 <br>
     * version: 1.0 <br>
     * date: 2020/9/24 21:15 <br>
     * author: Chazz <br>
     * @param goods 商品对象
     * @return double 金额小结
     */
    public double count(GoodsInfo goods){
        double totalPrice = 0;
        Double price = new PriceDaoImpl().selectPrice(goods.getId());
        Integer categoryId = new PriceDaoImpl().selectCategoryId(goods.getId());
        double discount = new DiscountDaoImpl().selectDiscountById(categoryId);
        if (discount < 1) {
            double afterDiscountPrice = new IsDiscountServiceImpl()
                .afterDiscount(categoryId, goods.getCount(), price);
            totalPrice  += afterDiscountPrice;
        }else {
            totalPrice = Double.parseDouble(new CoupondServiceImpl()
                .isCoupond(goods.getId(), goods.getGoodsId(), goods.getCount()));
        }
        return totalPrice;
    }
}
